package com.angel.activity;

import com.angel.util.BaseUtil;
import com.angel.util.ConstUtil;
import com.umeng.analytics.MobclickAgent;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RelativeLayout;
import android.widget.TabHost;
import android.widget.TextView;

/*底部菜单单*/
public class BottomMeunTab extends TabActivity{
        private static final String MAIN_TAB="main_tab";
        private static final String SEARCH_TAB="search_tab";
        private static final String MY_ACIT_TAB="my_acti_tab";
        private static final String WILL_MENU_TAB="will_menu_tab";
        private TabHost tabHost;
       // private LinearLayout mainradioBtn,searchRadioBtn,myradioBtn,willradioBtn;
        private LinearLayout linearLayout; 
   //     private RadioGroup radioGroup;
        private RelativeLayout mainradioBtn,searchRadioBtn,myradioBtn,willradioBtn;
        private Intent tent,intent;
        private Bundle bundle;
        private String fromIntent;//获取传递的Intent对象
        private MyOnClickListener listener;
        private ImageView mainImg;
        private TextView mainText;
        private ImageView imgBarOne,imgBarTwo,imgBarThree,imgBarFour;//菜单点击后底部条框
        @Override
		protected void onCreate(Bundle savedInstanceState) {
			super.onCreate(savedInstanceState);
			requestWindowFeature(Window.FEATURE_NO_TITLE);
			MobclickAgent.updateOnlineConfig(this);//友盟在线动态更改设置
		    setContentView(R.layout.bottom_menu);
		    /*获取底部菜单id*/
		    linearLayout=(LinearLayout)findViewById(R.id.linear);
		    mainradioBtn=(RelativeLayout)findViewById(R.id.main_acti_bottom_barid);
		    searchRadioBtn=(RelativeLayout)findViewById(R.id.sear_acti_bottom_barid);
		    myradioBtn=(RelativeLayout)findViewById(R.id.my_acti_bottom_barid);
		    willradioBtn=(RelativeLayout)findViewById(R.id.will_acti_bottom_barid);
			/*获取底部菜单选项图片*/
		    mainImg=(ImageView)findViewById(R.id.main_img_id);
		    mainText=(TextView)findViewById(R.id.main_txt);
		    /*菜单点击后底部条框id*/
		    imgBarOne=(ImageView)findViewById(R.id.img_bar_one_topid);
		    imgBarTwo=(ImageView)findViewById(R.id.img_bar_top_two_id);
		    imgBarThree=(ImageView)findViewById(R.id.img_bar_three_topid);
		    imgBarFour=(ImageView)findViewById(R.id.img_bar_four_topid);
		    /*获取从哪个activity跳转回来*/
			tent=getIntent();
			String mainJsonData=tent.getStringExtra("jsonData");
		    fromIntent=tent.getStringExtra("activity");
		    
			tabHost=getTabHost();
			if(mainJsonData!=null){
				intent=new Intent(BottomMeunTab.this,MainActivity.class);
				intent.putExtra("jsonData",mainJsonData);
			}
			
			tabHost.addTab(tabHost.newTabSpec(MAIN_TAB)
					.setIndicator(MAIN_TAB).setContent(intent));
			tabHost.addTab(tabHost.newTabSpec(SEARCH_TAB)
					.setIndicator(SEARCH_TAB).setContent(new Intent(BottomMeunTab.this,SearchActivity.class)));
			tabHost.addTab(tabHost.newTabSpec(MY_ACIT_TAB)
					.setIndicator(MY_ACIT_TAB).setContent(new Intent(BottomMeunTab.this,MyActivity.class)));
			tabHost.addTab(tabHost.newTabSpec(WILL_MENU_TAB)
					.setIndicator(WILL_MENU_TAB).setContent(new Intent(BottomMeunTab.this,WilingMenuActivity.class)));
			
			
		    
			/*监听底部菜单事件*/
			listener=new MyOnClickListener();
			mainradioBtn.setOnClickListener(listener);
			searchRadioBtn.setOnClickListener(listener);
			myradioBtn.setOnClickListener(listener);
			willradioBtn.setOnClickListener(listener);
			   //设置选择后的菜单背景颜色或登录默认背景颜色
			setBackground(R.drawable.bottombar_check_bottom_bar);
		}
		class MyOnClickListener implements OnClickListener{
			public void onClick(View v){
				int id=v.getId();
				if(id==R.id.main_acti_bottom_barid){
				mainradioBtn.setBackgroundResource(R.drawable.bottombar_check_bottom_bar);
				imgBarOne.setBackgroundResource(R.drawable.bottombar_check_top_bar);
				recoverBackground(R.id.main_acti_bottom_barid);
				tabHost.setCurrentTabByTag(MAIN_TAB);
				}else if(id==R.id.sear_acti_bottom_barid){
					searchRadioBtn.setBackgroundResource(R.drawable.bottombar_check_bottom_bar);
					imgBarTwo.setBackgroundResource(R.drawable.bottombar_check_top_bar);
					tabHost.setCurrentTabByTag(SEARCH_TAB);
					recoverBackground(R.id.sear_acti_bottom_barid);
				}else if(id==R.id.my_acti_bottom_barid){
					myradioBtn.setBackgroundResource(R.drawable.bottombar_check_bottom_bar);
					imgBarThree.setBackgroundResource(R.drawable.bottombar_check_top_bar);
					tabHost.setCurrentTabByTag(MY_ACIT_TAB);
					recoverBackground(R.id.my_acti_bottom_barid);
				}else if(id== R.id.will_acti_bottom_barid){
					willradioBtn.setBackgroundResource(R.drawable.bottombar_check_bottom_bar);
					imgBarFour.setBackgroundResource(R.drawable.bottombar_check_top_bar);
					tabHost.setCurrentTabByTag(WILL_MENU_TAB);
					recoverBackground(R.id.will_acti_bottom_barid);
				}
			}
		}
		
		//登陆时候底部主推菜单默认点击背景
		public void setBackground(int resource){
		    if(fromIntent==null||fromIntent.equals(ConstUtil.MAINACTIVITY)){
		    	mainradioBtn.setBackgroundResource(R.drawable.bottombar_check_bottom_bar);
				imgBarOne.setBackgroundResource(R.drawable.bottombar_check_top_bar);
			}else if(fromIntent.equals(ConstUtil.SEARCHACTIVITY)){
			 	searchRadioBtn.setBackgroundResource(resource);
			}else if(fromIntent.equals(ConstUtil.MYACTIVITY)){
				myradioBtn.setBackgroundResource(resource);
			}else if(fromIntent.equals(ConstUtil.WILLACTIVITY)){
			  	willradioBtn.setBackgroundResource(resource);
			}	    
	    }
		public void recoverBackground(int resource){
            if(resource==R.id.main_acti_bottom_barid){
				searchRadioBtn.setBackgroundResource(0x00000000);
				imgBarTwo.setBackgroundColor(getResources().getColor(R.color.white));
				myradioBtn.setBackgroundColor(0x00000000);
				imgBarThree.setBackgroundColor(getResources().getColor(R.color.white));
				willradioBtn.setBackgroundResource(0x00000000);
				imgBarFour.setBackgroundColor(getResources().getColor(R.color.white));
            }else if(resource==R.id.sear_acti_bottom_barid){
            	mainradioBtn.setBackgroundColor(0x00000000);
				imgBarOne.setBackgroundColor(getResources().getColor(R.color.white));
				myradioBtn.setBackgroundColor(0x00000000);
				imgBarThree.setBackgroundColor(getResources().getColor(R.color.white));
				willradioBtn.setBackgroundResource(0x00000000);
				imgBarFour.setBackgroundColor(getResources().getColor(R.color.white));
            }else if(resource==R.id.my_acti_bottom_barid){
            	mainradioBtn.setBackgroundColor(0x00000000);
				imgBarOne.setBackgroundColor(getResources().getColor(R.color.white));
				searchRadioBtn.setBackgroundResource(0x00000000);
				imgBarTwo.setBackgroundColor(getResources().getColor(R.color.white));
				willradioBtn.setBackgroundResource(0x00000000);
				imgBarFour.setBackgroundColor(getResources().getColor(R.color.white));
            }else if(resource==R.id.will_acti_bottom_barid){
				mainradioBtn.setBackgroundColor(0x00000000);
				imgBarOne.setBackgroundColor(getResources().getColor(R.color.white));
				searchRadioBtn.setBackgroundResource(0x00000000);
				imgBarTwo.setBackgroundColor(getResources().getColor(R.color.white));
				myradioBtn.setBackgroundColor(0x00000000);
				imgBarThree.setBackgroundColor(getResources().getColor(R.color.white));
			}
		}
        protected void onStart(){
        	super.onStart();
        }
		
}
